package top.healthylife.gateway.platform.lexin.dto.lexinfraud.res;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author : GaoZeXi
 * @date 2021/9/9 15:32
 */
@Data
@Accessors(chain = true)
@ApiModel("晶信欺诈分")
public class JxFraud {
    @ApiModelProperty(value = "晶信欺诈分", example = "[300.000,900.000],模型评分(保留3位小数)", required = false, notes = "通过用户的综合行为和三方数据评定其欺诈风险评分")
    private String jxFraudScore;

    @ApiModelProperty(value = "晶信欺诈等级", example = "1，2，3，4，5 -1 为未查得,等级", required = false, notes = "根据贷前数据和综合三方数据，综合评定其欺诈等级")
    private String jxFraudLev;

    @ApiModelProperty(value = "晶信欺诈分-反解析京东分", example = "", required = false, notes = "")
    private String jdModuleJxFraudScore;

//    public static void main(String[] args) {
//        JxFraud jxFraud = new JxFraud().setJxFraudScore("511.26");
//        System.out.println("jdModuleJxFraudScore = " + jxFraud.getJdModuleJxFraudScore());
//    }


    public String getJdModuleJxFraudScore() {
        int minOri = 300;
        int maxOri = 900;
        int minNew = 0;
        int maxNew = 1;
        int diffMaxMinOri = maxOri - minOri;
        int diffMaxMinNew = maxNew - minNew;
        float v;
        try {
            v = Float.parseFloat(this.jxFraudScore);
        } catch (Exception e) {
            return "-1";
        }
        if (ObjectUtil.isNull(v) || v < 0) {
            return "-1";
        } else {
            float xNew = minNew + ((v - minOri) / diffMaxMinOri) * diffMaxMinNew;
            if (xNew < minNew || xNew > maxNew) {
                return "-1";
            }
            return NumberUtil.roundStr(xNew, 5);
        }
    }
}
